import collections


class Solution(object):
    def validPath(self, n, edges, source, destination):
        d = collections.defaultdict(set)
        for u, v in edges:
            d[u].add(v)
            d[v].add(u)
        p = [0] * n

        def search(u):
            for v in d[u]:
                if not p[v]:
                    p[v] = 1
                    search(v)
        p[source] = 1
        search(source)
        return p[destination] == 1